/*
 *	Copyright (C) 2008 CRIMERE
 *	Copyright (C) 2008 Jean-Marc Mercier
 *	
 *	This file is part of OTS (optimally transported schemes), an open-source library
 *	dedicated to scientific computing. http://code.google.com/p/optimally-transported-schemes/
 *
 *	CRIMERE makes no representations about the suitability of this
 *	software for any purpose. It is provided "as is" without express or
 *	implied warranty.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "IOFacilities.h"
namespace IOFacilities {


std::ostream& operator<< (std::ostream& o, const std::vector<OS_double> & t)
{
    o << "( ";
	std::vector<OS_double>::const_iterator beg_ = t.begin(), end_ = t.end(), pred_ = t.end();
	--pred_;
    for (;beg_ != end_;++beg_) {
          o << *beg_;
		 if (beg_ != pred_)
			 o << ",";
    };
    o << " )";
    return o;
};

template <class Key, class V >
std::ostream& operator<< (std::ostream& o, const std::vector<OS_double> & t)
{
    o << "( ";
	std::vector<OS_double>::const_iterator beg_ = t.begin(), end_ = t.end(), pred_ = t.end();
	--pred_;
    for (;beg_ != end_;++beg_) {
          o << *beg_;
		 if (beg_ != pred_)
			 o << ",";
    };
    o << " )";
    return o;
};

std::istream &operator>>(std::istream &in, std::vector<OS_double> & t)
{
	char c;
	in >> c;
  if (c != '(') {
    in.setstate(std::ios_base::failbit);
    return in;
  }
   do {
		  OS_double temp;
          in >> temp;
		  in >> c;
		  t.push_back(temp);
		} while (c == ',');
  if (c != ')') in.setstate(std::ios_base::failbit);
  return in;
};


}